import os, hashlib, random
import application02.utils.cache_utils as cache_utils
import application02.utils.apollo_utils as apollo_utils

basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
    # 获取缓存参数
    cache_utils = cache_utils.CacheUtils()
    # apollo_until = apollo_utils.ApolloUtils()
    # 将一个随机数字符串输入 MD5，对其进行哈希
    m = hashlib.md5()
    data = str(random.random())
    m.update(data.encode("utf-8"))
    # 如果生产环境需要验证登录信息
    # if os.environ.get("env") == "prd" and apollo_until.get_apollo("is_need_login"):
    if os.environ.get("env") == "default":
        SECRET_KEY = m.hexdigest().upper()
        cache_utils.set_data("xx:flask:session", SECRET_KEY)
    else:
        SECRET_KEY = cache_utils.get_data("xx:flask:session")
    ITEMS_PER_PAGE = 10
    JWT_AUTH_URL_RULE = "/api/auth"

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    DEBUG = True


class TestingConfig(Config):
    TESTING = True


class ProductionConfig(Config):
    PRODUCTION = True


env_config = {
    "dev": DevelopmentConfig,
    "test": TestingConfig,
    "prd": ProductionConfig,
    "default": DevelopmentConfig,
}
